﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using Dukou.Example.Core.Dao;
using Dukou.Example.Core.Domain;
using NHibernate;
using Spring.Data.NHibernate.Support;
using Spring.Data.NHibernate.Generic;
using Dukou.Example.Core.BizService;
using Dukou.Web.Mvc.Extensions;
using Dukou.Domain;
using Dukou.Core.Domain;
using Dukou.Example.Core.QueryDomain;

namespace Dukou.Example.Core
{
    class Program
    {
        static void Main(string[] args)
        {
            IApplicationContext context = ContextRegistry.GetContext();

            context.ConfigureObject(HtmlHelperEntension.BizServiceWrapper, "dukou_web_mvc_htmlhelper");
            
            using (SessionScope scope = new SessionScope(true))
            {
                //scope.Open();
                //template.SessionFactory.GetCurrentSession().FlushMode = FlushMode.Auto;
                IUserBizService userBizService = (IUserBizService)context.GetObject("UserBizService");

                while (true)
                {
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IList<UserQuery> users = userBizService.Query();
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    Console.ReadKey();
                }
 
                //User user = userBizService.FindById(16);
                //user = userBizService.FindById(user.Id);
                //user = userBizService.FindById(user.Id);
                //user = userBizService.FindById(user.Id);
                //user = userBizService.FindById(user.Id);

                //userBizService.Save(new User() { Email = "matt.fang@live.cn", Password = "123456" });



                //EnumerationCategory c = HtmlHelperEntension.BizServiceWrapper.EnumerationBizService.FindCategoryByName(EnumerationCategories.Gender);
                //Console.WriteLine(c.Description);

                ////HtmlHelperEntension.BizServiceWrapper.EnumerationBizService.SelectByCategory(1);

                //IList<Enumeration> es = HtmlHelperEntension.BizServiceWrapper.EnumerationBizService.SelectByCategory(EnumerationCategories.Education);
                //foreach (var item in es)
                //{
                //    Console.WriteLine(item.Description);
                //}

                //user.State = UserState.New;
                //userDao.SaveOrUpdate(user);

                //User user2 = new User() { UserName = "matt.fang", Email = "matt.fang@live.cn", Id = user.Id };

                //User user3 = userDao.Merge(user2);

                //scope.SessionFactory.GetCurrentSession().Flush();

                //scope.SessionFactory.OpenSession().Clear();
            }

            Console.Read();
        }
    }
}
